package com.ycsd.invest.order.business.listplugin;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.form.FormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.events.BeforeCreateListDataProviderArgs;
import kd.bos.form.events.HyperLinkClickArgs;
import kd.bos.form.events.SetFilterEvent;
import kd.bos.mvc.list.ListDataProvider;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.epm.eb.formplugin.AbstractListPlugin;

import java.util.List;

/**
 * 列表插件
 */
public class TestStudyList extends AbstractListPlugin {

    /**
     * 构建列表取数器之前，触发此事件
     * @param args
     */
    @Override
    public void beforeCreateListDataProvider(BeforeCreateListDataProviderArgs args) {
        args.setListDataProvider(new ListDataProvider() {
            @Override
            public DynamicObjectCollection getData(int i, int j) {
                DynamicObjectCollection data = super.getData(i, j);
                if(data.size() > 0 && data.get(0).getDataEntityType().getProperties().containsKey("remark")) {
                    for (DynamicObject dynamicObject : data) {
                        dynamicObject.set("remark", "列表插件设置默认备注");
                    }
                }
                return data;
            }
        });
    }

    //设置过滤器
    @Override
    public void setFilter(SetFilterEvent e) {
//        List<QFilter> qFilters = e.getQFilters();
//        qFilters.add(new QFilter("valid", QCP.equals, true));
    }

    //列表超链接点击事件
    @Override
    public void billListHyperLinkClick(HyperLinkClickArgs args) {
        args.setCancel(true);
        FormShowParameter formShowParameter = new FormShowParameter();
        formShowParameter.setFormId("ycsd_test_alert");
        formShowParameter.getOpenStyle().setShowType(ShowType.Modal);
        this.getView().showForm(formShowParameter);
    }
}
